package com.mz.ozy.mvp.presenter;


import android.app.Activity;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.GoodsSpecBean;
import com.mz.ozy.bean.ShopDetailBean;
import com.mz.ozy.bean.ShopSpecListBean;
import com.mz.ozy.bean.VirtualGoodsBean;
import com.mz.ozy.bean.VirtualOrderBean;
import com.mz.ozy.mvp.model.ShopDetailModel;
import com.mz.ozy.mvp.model.VirtualGoodsModel;
import com.mz.ozy.mvp.view.ShopDetailContract;
import com.mz.ozy.mvp.view.VirtualGoodsContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;


/**
 * @author
 * @date 2018/7/25
 * @description
 */

public class VirtualGoodsPresenter extends BasePresenterImpl<VirtualGoodsContract.View> implements VirtualGoodsContract.Presenter {
    private VirtualGoodsModel mShopDetailModel;

    public VirtualGoodsPresenter() {
        super();
        mShopDetailModel = new VirtualGoodsModel();
    }

    @Override
    public void obtainShopDetailInfo(Activity activity, String goodsId) {
        mShopDetailModel.obtainShopDetailInfo(activity, goodsId)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<VirtualGoodsBean>(mView) {
                    @Override
                    public void onSuccesss(VirtualGoodsBean shopDetailBean) {
                        mView.obtainShopDetailInfoSuccess(shopDetailBean);
                    }
                });
    }

    @Override
    public void onJoinCar(Activity activity, String goodsID, String ggId, String buyNumber) {

        mShopDetailModel.onJoinCar(activity, goodsID, ggId, buyNumber)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.onJoinCarSuccess(jsonObject);
                    }
                });


    }

    @Override
    public void onGoodsFollow(Activity activity, String gid) {
        mShopDetailModel.onGoodsFollow(activity, gid)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.onGoodsFollowSuccess(jsonObject);
                    }
                });
    }

    @Override
    public void onBuy(Activity activity, String goodsId, String type, String gid, String num) {
        mShopDetailModel.onBuy(activity, goodsId, type, gid, num)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<VirtualOrderBean>(mView) {
                    @Override
                    public void onSuccesss(VirtualOrderBean jsonObject) {
                        mView.onBuySuccess(jsonObject);
                    }
                });

    }
}
